package org.common.eureka.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.common.eureka.service.IOrderService;
import org.common.eureka.vo.Result;
import org.sam.commons.entity.dto.BusiOrderDto;
import org.sam.commons.entity.dto.BusiOrderQueryDto;
import org.sam.commons.entity.pojo.BusiOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单
 *
 * @author samphin
 * @since 2020-6-14 13:02:07
 */
@RestController
@Api("OrderController相关的api")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @ApiOperation(value = "保存订单信息", notes = "保存订单信息")
    @PostMapping("/order")
    public Result save(@RequestBody BusiOrderDto orderDto) {
        this.orderService.save(orderDto);
        return Result.ok();
    }

    @ApiOperation(value = "查询订单信息", notes = "查询数据库中某个的订单信息")
    @GetMapping("/order/all")
    public Result queryList(@ModelAttribute BusiOrderQueryDto queryDto) {
        List<BusiOrder> users = this.orderService.queryList(queryDto);
        return Result.ok().setData(users);
    }

    @ApiOperation(value = "根据id查询订单信息", notes = "查询数据库中某个的订单信息")
    @GetMapping("/order/{id}")
    public Result queryDetail(@PathVariable Long id) {
        BusiOrder detail = this.orderService.queryById(id);
        return Result.ok().setData(detail);
    }

    /**
     * 秒杀商品
     * @param orderDto
     * @return
     */
    @PostMapping("/seckill")
    public Result secKill(@RequestBody BusiOrderDto orderDto) {
        this.orderService.save(orderDto);
        return Result.ok();
    }
}
